package com.xuqi.DownLoad;

import java.io.File;
import java.io.IOException;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.xuqi.R;
import com.xuqi.W3.StorageAdapter;
import com.xuqi.menucontrol.SCR_MenuBase;

public class DownLoadMain extends SCR_MenuBase
{

	protected static final String TAG = "DownLoadMain";
	private EditText m_EditText = null;
	private Button m_Button = null;
	private TextView m_TextView = null;
	final String strpath = "/sdcard/";

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.download);
		m_EditText = (EditText) findViewById(R.id.path);
		m_EditText.setText("http://www.moorburn.com/cache/wp/2011/06/mouse-hands.jpg");
		m_Button = (Button) findViewById(R.id.download);
		m_TextView = (TextView) findViewById(R.id.Result);
		final W3DownloadControl downloadControl = new W3DownloadControl();
		downloadControl.setCallBack(new W3DownloadControl.DownloadCallBack()
		{

			@Override
			public void downloadStart(String fileName)
			{
				// TODO Auto-generated method stub

			}

			@Override
			public void downloadTotalSize(int totalsize)
			{
				// TODO Auto-generated method stub

			}

			@Override
			public void downloadProgress(String fileName, int progress)
			{
				// TODO Auto-generated method stub
				Log.d(TAG,"progress:" + progress);
			}

			@Override
			public void downloadFinished(String fileName, int result)
			{
				// TODO Auto-generated method stub
				// m_TextView.setText(fileName);
				m_TextView.setText(strpath);
			}
		});

		m_Button.setOnClickListener(new View.OnClickListener()
		{

			@Override
			public void onClick(View v)
			{
				// TODO Auto-generated method stub
				downloadControl.init();

				downloadControl.downloadFile(m_EditText.getText().toString(),strpath+"1.jpg");

			}
		});

	}

}
